package com.sport.facilities.booking.system.ui;

import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.GridView;

import com.sport.facilities.booking.system.R;

public class ButtonAdapter extends BaseAdapter {
	private Context mContext;

	// Gets the context so it can be used later
	public ButtonAdapter(Context c) {
		mContext = c;
	}

	public String[] filesnames = { "Cancel Booking", "Make Booking",
			"Confirm Booking", "Transfer Booking", "Inquire Booking Made",
			"Inquire Confirmed Booking", "Notice Board",
			"Sharing on Facebook", "Friend List" };

	// Total number of things contained within the adapter
	public int getCount() {
		return filesnames.length;
	}

	// Require for structure, not really used in my code.
	public Object getItem(int position) {
		return null;
	}

	// Require for structure, not really used in my code. Can
	// be used to get the id of an item in the adapter for
	// manual control.
	public long getItemId(int position) {
		return position;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		Button btn;
		if (convertView == null) {
			// if it's not recycled, initialize some attributes
			btn = new Button(mContext);
			//btn.setLayoutParams(new GridView.LayoutParams(160, 150));
			btn.setWidth(160);
			btn.setHeight(240);
			btn.setPadding(8, 8, 8, 8);
			//btn.setMaxWidth(88);
		} else {
			btn = (Button) convertView;
		}
		// exus

		// btn.setBackgroundColor(Color.BLACK);
		btn.setText(filesnames[position]);
		if(position == 0){
			btn.setBackgroundResource(R.xml.btn_selector_red);
		}
		else if(position == 1){
			btn.setBackgroundResource(R.xml.btn_selector_green);
		}
		else if(position == 2){
			btn.setBackgroundResource(R.xml.btn_selector_purple);
		}
		else if(position == 3){
			btn.setBackgroundResource(R.xml.btn_selector_yellow);
		}
		else if(position == 4){
			btn.setBackgroundResource(R.xml.btn_selector_blue);
		}
		else if(position == 5){
			btn.setBackgroundResource(R.xml.btn_selector_black);
		}
		else if(position == 6){
			btn.setBackgroundResource(R.xml.btn_selector_green);
		}
		else if(position == 7){
			btn.setBackgroundResource(R.xml.btn_selector_purple);
		}
		else if(position == 8){
			btn.setBackgroundResource(R.xml.btn_selector_yellow);
		}
		else if(position == 9){
			btn.setBackgroundResource(R.xml.btn_selector_red);
		}
		else{
			btn.setBackgroundResource(R.xml.btn_selector_blue);
			
		}
		
		
		btn.setTextColor(Color.WHITE);
		//btn.setBackgroundColor(R.style.ButtonText2);

		// btn.setBackgroundResource(R.style.ButtonText);
		// btn.setBackgroundColor(R.xml.btn_selector_blue);

		// filenames is an array of strings
		// btn.setTextColor(Color.BLACK);

		// btn.setBackgroundResource(R.drawable.button2);
		btn.setId(position);
		btn.setOnClickListener(new MyOnClickListener(position));
		return btn;
	}
}
